from elasticsearch import Elasticsearch

es = Elasticsearch(['219.224.134.226:9202'])

index_info = {
    'settings': {
        'number_of_replicas': 1,
        'number_of_shards': 5
    },
    "mappings": {
    }
}
one_type = {
    "properties": {
        "ask_name": {
            "index": "not_analyzed",
            "type": "string"
        },
        "ask_text": {
            "index": "not_analyzed",
            "type": "string"
        },
        "company": {
            "index": "not_analyzed",
            "type": "string"
        },
        "answer_text": {
            "index": "not_analyzed",
            "type": "string"
        },
        "ask_ts": {
            "type": "long"
        },
        "answer_ts": {
            "type": "long"
        },
        "ask_date": {
            "index": "not_analyzed",
            "type": "string"
        },
        "answer_date": {
            "index": "not_analyzed",
            "type": "string"
        }
    }
}
index_name = 'info'
for type in ['cn', 'see']:
    index_info["mappings"].update({type: one_type})

exist_indice = es.indices.exists(index=index_name)
if not exist_indice:
    es.indices.create(index=index_name, body=index_info, ignore=400)
else:
    es.indices.delete(index=index_name)
    es.indices.create(index=index_name, body=index_info, ignore=400)
